package cn.com.zero.file.config;

import cn.com.zero.file.config.properties.FileUploadProperties;
import cn.com.zero.file.constants.FileUploadConstant;
import cn.com.zero.file.service.IFileService;
import cn.com.zero.file.service.impl.LocalFileServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author liuxh
 * @version 1.0.0
 * @Description 本地配置
 * @createTime 2022/9/13
 */
@Configuration
@EnableConfigurationProperties({FileUploadProperties.class})
@ConditionalOnProperty(name = "zero.file.type", havingValue = FileUploadConstant.FILE_TYPE_LOCAL, matchIfMissing = true)
public class LocalFileConfig {

    @Value("${zero.local.path}")
    private String localFilePath;

    @Bean
    public IFileService fileService(FileUploadProperties fileUploadProperties) {
        return new LocalFileServiceImpl(localFilePath, fileUploadProperties);
    }

}
